package com.yunzhong.appointment.system.controller;

import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.yunzhong.appointment.entity.Department;
import com.yunzhong.appointment.entity.Person;
import com.yunzhong.appointment.entity.Scheduling;
import com.yunzhong.appointment.system.page.DoctorPage;
import com.yunzhong.appointment.system.service.DoctorService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.RequestMapping;

import javax.servlet.http.HttpServletRequest;
import java.util.List;
import java.util.Set;

/**
 * 人员科室
 * 刘凡博
 */
@Controller
public class DoctorController {
    @Autowired
    private DoctorService doctorService;

    /**
     * 根据科室的id 跳转到对应科室医生预约的页面
     * @param id
     * @param mm
     * @param request
     * @return
     */
    @RequestMapping("doctor/queryByKsId")
    public String queryByKsId(String id, ModelMap mm, HttpServletRequest request, DoctorPage page){
        Department dp = doctorService.queryksById(id, page);
        PageHelper.startPage(page.getPageNum(), page.getPageSize());
        List<Person> person = doctorService.queryByKsId(page,id);
        mm.addAttribute("pageInfo", new PageInfo<Person>(person));
        mm.addAttribute("page", page);
        mm.addAttribute("dp", dp);
        return "appointment/doctor/listDoctor";

    }

    /**
     * 根据人员主键查询医生信息
     * @param id
     * @param mm
     * @param request
     * @return
     */
    @RequestMapping("doctor/queryDoctor")
    public String queryDoctor(String id, ModelMap mm, HttpServletRequest request,Integer year){
        Person person = doctorService.queryDoctorById(id);
        mm.put("person",person);
        //根据医生主键查询出诊时间
        List<Scheduling> scheduling = doctorService.selectSchedulingTime(id,year);
        mm.put("scheduling", scheduling);
        //查询出诊时间,不要重复,排序
        Set<String> set = doctorService.selectTime(scheduling);
        mm.put("set", set);
        return  "appointment/appt/apptinfo";
    }

}
